package reflect.hhh;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws Exception{
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入类名");
        String lname = scan.nextLine();
        Class cls=Class.forName(lname);
        Method[]methods=cls.getDeclaredMethods();
        if(cls.isAnnotationPresent(AutoRunClass.class))
        {
            System.out.println("类上存在注解");
            Object obj=cls.newInstance();
            System.out.println(obj);
            for(Method m:methods){
                if(m.isAnnotationPresent(AutoRunMethod.class)){
                m.setAccessible(true);
                m.invoke(obj);
                }
            }
        }else{
            System.out.println("类上不存在注解");
        }
    }
}
